<?php
/**
 * @version      BOSSCMS-Free
 * @trademark    BOSSCMS
 * @copyright    Copyright © by BOSSCMS-Free (https://www.bosscms.net/) 保留所有权利
 * @license      https://gitee.com/Greenpeas/BOSSCMS/license/ 和 https://www.bosscms.net/freelicense/
 * @link         https://www.bosscms.net/
 * @author       温州软界网络技术有限公司
**/
defined('IS_OK') or exit('Access Forbidden');
define('IS_LOGIN', true);

into::basic_class('admin');

class login extends admin
{
	public function init()
	{
		global $G;
		$G['no_copyright'] = true;
		$G['no_easy'] = true;
		$data['username'] = isset($G['get']['username'])?$G['get']['username']:arrExist($G,'cookie|admin_login_username');
		echo $this->theme('login/login',$data);
	}
	
	public function check()
	{
		global $G;
		into::basic_class('captcha');
		if($G['config']['admin_login_captcha']){
			if(!isset($G['post']['captcha']) || empty($G['post']['captcha'])){
				alert('请填写验证码');
			}
			if($G['post']['captcha']!=session::get('captcha')){
				alert('验证码错误');
			}
		}
		if(isset($G['post']['password']) && !empty($G['post']['username'])){
			if($result = mysql::select_one('id,open,frequency,username,password','manager',"username='{$G['post']['username']}' AND password='".md5($G['post']['password'])."'")){
				if($result['open']){
					mysql::update(array('ip'=>getIP(),'ltime'=>TIME,'frequency'=>$result['frequency']+1),'manager',"id='{$result['id']}'");
					session::set('manager',$result['id'].P.$result['username'].P.md5($result['password']).P.TIME, 28888);
					if(arrExist($G['post'],'save') || ($G['post']['username']==arrExist($G,'cookie|admin_login_username'))){
						setcookie("admin_login_username", $G['post']['username'], TIME+3122064000, '/', null, null, true);
					}
					alert('登录成功','./');
				}else{
					alert('该用户没有启用');
				}
			}else{
				if($G['post']['username']==arrExist($G,'cookie|admin_login_username')){
					setcookie("admin_login_username", '', TIME-1, '/', null, null, true);
				}
				alert('用户或密码错误，请重新输入');
			}
		}else{
			alert('没有提交信息');
		}
	}
	
	public function logout()
	{
		global $G;
		session::clear('manager');
		alert('登出成功',url::mpf('login','login','init'));
	}
}
?>